package nessie;

/**
 * this nifty little class handles the controller strobes. it is similar to simply polling the controller ports(p1=0x4016, p2=0x4017) to find out if a button has been pressed.
 * when a certain code is written to the controller ports, the button states are copied to the memory address behind the same ports.
 */
public class Controller {

    private static byte keyArray = 0;

    private Controller() {
    }

    public static byte getP1Input() {
        byte lsbOrOpenbus = (byte) ((1 & keyArray) | 0x40);
        //A B SE ST U D L R
        //0 1 2  3  4 5 6 7

        keyArray >>= 1;
        keyArray |= 128;
        return lsbOrOpenbus;
    }

    /**copy current button state to arbitrary buffer*/
    public static void setKeyArray() {
        keyArray = MainUI.pressedKeysBitmask;
    }
}
